﻿Imports Microsoft.VisualBasic
Imports System.Data
Partial Public Class Service
#Region "客户信息判断"
    Public Function _Bill_Property14_CheckCustom(ByVal FName As String, ByVal FCName As String, ByRef FCid As Integer, ByRef ErrString As String) As Boolean
        Try
            If FName.Trim = String.Empty Then
                ErrString = "参数不正确"
                Return False
            End If
            Dim sqlstr As String = String.Empty
            Dim ds As New DataSet
            If FCid > 0 Then
                '--有ID,更新
                sqlstr = String.Format("update Base_Property14 set FName='{0}',FCName='{1}' where id={3} and FType=0", FName.Trim, FCName.Trim, FCid)
                Return DControl.ExecSQL(sqlstr, ErrString)
            Else
                '--没ID判断是否新增
                sqlstr = String.Format("select * from Base_Property14 where FName='{0}' and FType=0", FName.Trim)
                If DControl.QuerySQL(sqlstr, ds, ErrString) = False Then
                    Return False
                End If
                If ds.Tables(0).Rows.Count < 1 Then
                    '--新增
                    sqlstr = String.Format("insert into Base_Property14(FName,FCName,FType) values('{0}','{1}',0);select @@IDENTITY as FID", FName.Trim, FCName.Trim)
                    ds = New DataSet
                    If DControl.QuerySQL(sqlstr, ds, ErrString) = False Then
                        Return False
                    End If
                    FCid = ds.Tables(0).Rows(0).Item("FID")
                    Return True
                Else
                    '--更新
                    FCid = ds.Tables(0).Rows(0).Item("id")
                    sqlstr = String.Format("update Base_Property14 set FName='{0}',FCName='{1}' where id={3} and FType=0", FName.Trim, FCName.Trim, FCid)
                    Return DControl.ExecSQL(sqlstr, ErrString)
                End If
            End If
        Catch ex As Exception
            ErrString = String.Format("检查客户信息时出现错误!{0}错误信息:{1}", vbCrLf, ex.Message)
            Return False
        End Try
    End Function
#End Region

#Region "检查商品信息"
    Public Function _Bill_Property14_CheckItem(ByVal FName As String, ByVal FQty As Decimal, ByVal FPrice As Decimal, ByRef FCid As Integer, ByRef ErrString As String) As Boolean
        Try
            If FName.Trim = String.Empty Then
                ErrString = "参数不正确!"
                Return False
            End If
            Dim sqlstr As String = String.Empty
            Dim ds As New DataSet
            If FCid > 0 Then
                '--有ID,直接更新
                sqlstr = String.Format("update Base_Property14 set FName='{0}',FQty='{1}',FPrice='{2}' where id={3} and FType=1", FName.Trim, FQty, FPrice, FCid)
                Return DControl.ExecSQL(sqlstr, ErrString)
            Else
                '--没ID判断是否增加
                sqlstr = String.Format("select * from Base_Property14 where FName='{0}' and FType=1", FName.Trim)
                ds = New DataSet
                If DControl.QuerySQL(sqlstr, ds, ErrString) = False Then
                    Return False
                End If
                If ds.Tables(0).Rows.Count < 1 Then
                    '--增加
                    sqlstr = String.Format("insert into Base_Property14(FName,FQty,FPrice,FType) values('{0}','{1}','{2}',1);select @@IDENTITY as FID", FName.Trim, FQty, FPrice)
                    ds = New DataSet
                    If DControl.QuerySQL(sqlstr, ds, ErrString) = False Then
                        Return False
                    End If
                    FCid = ds.Tables(0).Rows(0).Item("FID")
                    Return True
                Else
                    '--更新
                    FCid = ds.Tables(0).Rows(0).Item("id")
                    sqlstr = String.Format("update Base_Property14 set FName='{0}',FQty='{1}',FPrice='{2}' where id={3} and FType=1", FName.Trim, FQty, FPrice, FCid)
                    Return DControl.ExecSQL(sqlstr, ErrString)
                End If
            End If
        Catch ex As Exception
            ErrString = String.Format("检查项目信息时出现错误!{0}错误信息:{1}", vbCrLf, ex.Message)
            Return False
        End Try
    End Function
#End Region

#Region "获取客户或项目列表"
    Public Function _BILL_Property14_GetItemList(ByVal FSession As String, ByRef DsArr As Byte(), ByVal FStyle As String, ByRef ErrString As String) As Boolean Implements IService._BILL_Property14_GetItemList
        If FVerifyUser(FSession, ErrString) = False Then
            Return False
        End If
        Try
            Dim sqlstr As String = "select * from Base_Property14"
            Dim ds As New DataSet
            Select Case FStyle
                Case "ITEM"
                    sqlstr += " where FType=1"
                Case "CUSTOM"
                    sqlstr += " where FType=0"
                Case Else
                    ErrString = "参数错误"
                    Return False
            End Select
            If DControl.QuerySQL(sqlstr, ds, ErrString) = False Then
                Return False
            End If
            DsArr = FControl.CvtDs(ds)
            Return True
        Catch ex As Exception
            ErrString = String.Format("查询时发生错误!{0}错误信息:{1}", vbCrLf, ex.Message)
            Return False
        End Try
    End Function
#End Region

#Region "获取客户或项目信息"
    Public Function _BILL_Property14_GetItemInfo(ByVal FSession As String, ByRef FCinf As FBaseProp14, ByVal FStyle As String, ByRef ErrString As String) As Boolean Implements IService._BILL_Property14_GetItemInfo
        If FVerifyUser(FSession, ErrString) = False Then
            Return False
        End If
        Try
            Dim sqlstr As String = "select * from Base_Property14"
            Dim ds As New DataSet
            If FCinf Is Nothing Then
                ErrString = "参数不正确!"
                Return False
            End If
            If FCinf.id <= 0 Then
                ErrString = "参数不正确!"
                Return False
            End If
            Dim fcid As String = FCinf.id
            Dim FName As String = FCinf.FName
            FCinf = New FBaseProp14
            Select Case FStyle
                Case "CUSTOMID"
                    If fcid.Trim = String.Empty Then
                        ErrString = "参数错误"
                        Return False
                    End If
                    sqlstr += " where id=" & fcid.Trim & " and FType=0"
                    FCinf.FType = 0
                Case "CUSTOMNAME"
                    If FName.Trim = String.Empty Then
                        ErrString = "参数错误"
                        Return False
                    End If
                    sqlstr += " where FName='" & FName.Trim & " and FType=0"
                    FCinf.FType = 0
                Case "ITEMID"
                    If fcid.Trim = String.Empty Then
                        ErrString = "参数错误"
                        Return False
                    End If
                    sqlstr += " where id=" & fcid.Trim & " and FType=1"
                    FCinf.FType = 1
                Case "ITEMNAME"
                    If FName.Trim = String.Empty Then
                        ErrString = "参数错误"
                        Return False
                    End If
                    sqlstr += " where FName='" & FName.Trim & " and FType=1"
                    FCinf.FType = 1
                Case Else
                    ErrString = "参数错误"
                    Return False
            End Select
            If DControl.QuerySQL(sqlstr, ds, ErrString) = False Then
                Return False
            End If
            '--取信息
            If ds.Tables(0).Rows.Count < 1 Then
                ErrString = "未找到指定项目"
                Return False
            End If
            FCinf.id = FControl.cvN(ds.Tables(0).Rows(0).Item("id"))
            FCinf.FName = FControl.cvN(ds.Tables(0).Rows(0).Item("FName"))
            FCinf.FCName = FControl.cvN(ds.Tables(0).Rows(0).Item("FCName"))
            FCinf.FQty = FControl.cvN(ds.Tables(0).Rows(0).Item("FQty"))
            FCinf.FPrice = FControl.cvN(ds.Tables(0).Rows(0).Item("FPrice"))
            Return True
        Catch ex As Exception
            ErrString = String.Format("查询信息出错!{0}错误信息:{1}", vbCrLf, ex.Message)
            Return False
        End Try
    End Function
#End Region

#Region "保存单据"
    Public Function _Bill_Property14_SaveBill(ByVal FSession As String, ByVal FBinf As FBillProp14, ByVal FType As String, ByRef ErrString As String) As Boolean Implements IService._Bill_Property14_SaveBill
        If FVerifyUser(FSession, ErrString) = False Then
            Return False
        End If
        Try
            Dim sqlstr As String = String.Empty
            Dim ds As New DataSet
            Dim FUinf As New FUserInfo
            '--取用户信息
            If GetUserInfoBySession(FSession, FUinf, ErrString) = False Then
                Return False
            End If
            '--检查保存方式
            Select Case FType
                Case "New"
                    '--检查客户信息
                    If FBinf.FName.Trim = String.Empty Then
                        ErrString = "交款单位不能为空"
                        Return False
                    End If
                    If _Bill_Property14_CheckCustom(FBinf.FName, FBinf.FCName, FBinf.FCid, ErrString) = False Then
                        ErrString = String.Format("检查客户信息失败{0}错误信息:{1}", vbCrLf, ErrString)
                        Return False
                    End If
                    If FBinf.FCid < 1 Then
                        ErrString = "检查客户信息失败!未知错误"
                        Return False
                    End If
                    '--检查项目信息
                    If FBinf.FItemName1.Trim = String.Empty Then
                        ErrString = "第一条分录不能为空!"
                        Return False
                    End If
                    '--获取用户信息
                    If FBinf.FUid <> FUinf.id Then
                        ErrString = "参数错误!"
                        Return False
                    End If
                    '--定义SQL语句参数变量
                    Dim FCol As String = String.Empty
                    Dim FVal As String = String.Empty
                    '--检查第1条分录
                    If FBinf.FItemName1.Trim <> String.Empty Then
                        If FBinf.FItem1 = Nothing Or FBinf.FItem1 = 0 Then
                            '--增加项目
                            _Bill_Property14_CheckItem(FBinf.FItemName1, FBinf.FQty1, FBinf.FPrice1, FBinf.FItem1, ErrString)
                        End If
                        '--检查各项信息填写情况
                        If FBinf.FSDate1 = Nothing Or FBinf.FEDate1 = Nothing Then
                            ErrString = "第 1 行收费区间填写不正确!"
                            Return False
                        End If
                        If Math.Abs(DateDiff(DateInterval.Day, FBinf.FSDate1, FBinf.FEDate1)) + 1 <> FBinf.FQty1 Then
                            ErrString = "参数有误!"
                            Return False
                        End If
                        If FBinf.FQty1 <= 0 Then
                            ErrString = "第 1 行平米数必须大于0"
                            Return False
                        End If
                        If FBinf.FPrice1 <= 0 Then
                            ErrString = "第 1 行单价必须大于0"
                            Return False
                        End If
                        If FBinf.FDays1 <= 0 Then
                            ErrString = "第 1 行天数必须大于0"
                            Return False
                        End If
                        If FBinf.FDays1 * FBinf.FPrice1 * FBinf.FQty1 <> FBinf.FAcc1 Then
                            ErrString = "第 1 行金额有误!"
                            Return False
                        End If
                        '--组合条件
                        FCol += ",FItem1,FItemName1,FSDate1,FEDate1,FQty1,FPrice1,FDays1,FAcc1"
                        FVal += String.Format(",'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}'", FBinf.FItem1, FBinf.FItemName1, FBinf.FSDate1, FBinf.FEDate1, FBinf.FQty1, FBinf.FPrice1, FBinf.FDays1, FBinf.FAcc1)
                    End If

                    '--检查第2条分录
                    If FBinf.FItemName2.Trim <> String.Empty Then
                        If FBinf.FItem2 = Nothing Or FBinf.FItem2 = 0 Then
                            '--增加项目
                            _Bill_Property14_CheckItem(FBinf.FItemName2, FBinf.FQty2, FBinf.FPrice2, FBinf.FItem2, ErrString)
                        End If
                        '--检查各项信息填写情况
                        If FBinf.FSDate2 = Nothing Or FBinf.FEDate2 = Nothing Then
                            ErrString = "第 2 行收费区间填写不正确!"
                            Return False
                        End If
                        If Math.Abs(DateDiff(DateInterval.Day, FBinf.FSDate2, FBinf.FEDate2)) + 1 <> FBinf.FQty2 Then
                            ErrString = "参数有误!"
                            Return False
                        End If
                        If FBinf.FQty2 <= 0 Then
                            ErrString = "第 2 行平米数必须大于0"
                            Return False
                        End If
                        If FBinf.FPrice2 <= 0 Then
                            ErrString = "第 2 行单价必须大于0"
                            Return False
                        End If
                        If FBinf.FDays2 <= 0 Then
                            ErrString = "第 2 行天数必须大于0"
                            Return False
                        End If
                        If FBinf.FDays2 * FBinf.FPrice2 * FBinf.FQty2 <> FBinf.FAcc2 Then
                            ErrString = "第 2 行金额有误!"
                            Return False
                        End If
                        '--组合条件
                        FCol += ",FItem2,FItemName2,FSDate2,FEDate2,FQty2,FPrice2,FDays2,FAcc2"
                        FVal += String.Format(",'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}'", FBinf.FItem2, FBinf.FItemName2, FBinf.FSDate2, FBinf.FEDate2, FBinf.FQty2, FBinf.FPrice2, FBinf.FDays2, FBinf.FAcc2)
                    End If

                    '--检查第3条分录
                    If FBinf.FItemName3.Trim <> String.Empty Then
                        If FBinf.FItem3 = Nothing Or FBinf.FItem3 = 0 Then
                            '--增加项目
                            _Bill_Property14_CheckItem(FBinf.FItemName3, FBinf.FQty3, FBinf.FPrice3, FBinf.FItem3, ErrString)
                        End If
                        '--检查各项信息填写情况
                        If FBinf.FSDate3 = Nothing Or FBinf.FEDate3 = Nothing Then
                            ErrString = "第 3 行收费区间填写不正确!"
                            Return False
                        End If
                        If Math.Abs(DateDiff(DateInterval.Day, FBinf.FSDate3, FBinf.FEDate3)) + 1 <> FBinf.FQty3 Then
                            ErrString = "参数有误!"
                            Return False
                        End If
                        If FBinf.FQty3 <= 0 Then
                            ErrString = "第 3 行平米数必须大于0"
                            Return False
                        End If
                        If FBinf.FPrice3 <= 0 Then
                            ErrString = "第 3 行单价必须大于0"
                            Return False
                        End If
                        If FBinf.FDays3 <= 0 Then
                            ErrString = "第 3 行天数必须大于0"
                            Return False
                        End If
                        If FBinf.FDays3 * FBinf.FPrice3 * FBinf.FQty3 <> FBinf.FAcc3 Then
                            ErrString = "第 3 行金额有误!"
                            Return False
                        End If
                        '--组合条件
                        FCol += ",FItem3,FItemName3,FSDate3,FEDate3,FQty3,FPrice3,FDays3,FAcc3"
                        FVal += String.Format(",'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}'", FBinf.FItem3, FBinf.FItemName3, FBinf.FSDate3, FBinf.FEDate3, FBinf.FQty3, FBinf.FPrice3, FBinf.FDays3, FBinf.FAcc3)
                    End If

                    '--检查第4条分录
                    If FBinf.FItemName4.Trim <> String.Empty Then
                        If FBinf.FItem4 = Nothing Or FBinf.FItem4 = 0 Then
                            '--增加项目
                            _Bill_Property14_CheckItem(FBinf.FItemName4, FBinf.FQty4, FBinf.FPrice4, FBinf.FItem4, ErrString)
                        End If
                        '--检查各项信息填写情况
                        If FBinf.FSDate4 = Nothing Or FBinf.FEDate4 = Nothing Then
                            ErrString = "第 4 行收费区间填写不正确!"
                            Return False
                        End If
                        If Math.Abs(DateDiff(DateInterval.Day, FBinf.FSDate4, FBinf.FEDate4)) + 1 <> FBinf.FQty4 Then
                            ErrString = "参数有误!"
                            Return False
                        End If
                        If FBinf.FQty4 <= 0 Then
                            ErrString = "第 4 行平米数必须大于0"
                            Return False
                        End If
                        If FBinf.FPrice4 <= 0 Then
                            ErrString = "第 4 行单价必须大于0"
                            Return False
                        End If
                        If FBinf.FDays4 <= 0 Then
                            ErrString = "第 4 行天数必须大于0"
                            Return False
                        End If
                        If FBinf.FDays4 * FBinf.FPrice4 * FBinf.FQty4 <> FBinf.FAcc4 Then
                            ErrString = "第 4 行金额有误!"
                            Return False
                        End If
                        '--组合条件
                        FCol += ",FItem4,FItemName4,FSDate4,FEDate4,FQty4,FPrice4,FDays4,FAcc4"
                        FVal += String.Format(",'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}'", FBinf.FItem4, FBinf.FItemName4, FBinf.FSDate4, FBinf.FEDate4, FBinf.FQty4, FBinf.FPrice4, FBinf.FDays4, FBinf.FAcc4)
                    End If

                    '--检查第5条分录
                    If FBinf.FItemName5.Trim <> String.Empty Then
                        If FBinf.FItem5 = Nothing Or FBinf.FItem5 = 0 Then
                            '--增加项目
                            _Bill_Property14_CheckItem(FBinf.FItemName5, FBinf.FQty5, FBinf.FPrice5, FBinf.FItem5, ErrString)
                        End If
                        '--检查各项信息填写情况
                        If FBinf.FSDate5 = Nothing Or FBinf.FEDate5 = Nothing Then
                            ErrString = "第 5 行收费区间填写不正确!"
                            Return False
                        End If
                        If Math.Abs(DateDiff(DateInterval.Day, FBinf.FSDate5, FBinf.FEDate5)) + 1 <> FBinf.FQty5 Then
                            ErrString = "参数有误!"
                            Return False
                        End If
                        If FBinf.FQty5 <= 0 Then
                            ErrString = "第 5 行平米数必须大于0"
                            Return False
                        End If
                        If FBinf.FPrice5 <= 0 Then
                            ErrString = "第 5 行单价必须大于0"
                            Return False
                        End If
                        If FBinf.FDays5 <= 0 Then
                            ErrString = "第 5 行天数必须大于0"
                            Return False
                        End If
                        If FBinf.FDays5 * FBinf.FPrice5 * FBinf.FQty5 <> FBinf.FAcc5 Then
                            ErrString = "第 5 行金额有误!"
                            Return False
                        End If
                        '--组合条件
                        FCol += ",FItem5,FItemName5,FSDate5,FEDate5,FQty5,FPrice5,FDays5,FAcc5"
                        FVal += String.Format(",'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}'", FBinf.FItem5, FBinf.FItemName5, FBinf.FSDate5, FBinf.FEDate5, FBinf.FQty5, FBinf.FPrice5, FBinf.FDays5, FBinf.FAcc5)
                    End If

                    '--检查第6条分录
                    If FBinf.FItemName6.Trim <> String.Empty Then
                        If FBinf.FItem6 = Nothing Or FBinf.FItem6 = 0 Then
                            '--增加项目
                            _Bill_Property14_CheckItem(FBinf.FItemName6, FBinf.FQty6, FBinf.FPrice6, FBinf.FItem6, ErrString)
                        End If
                        '--检查各项信息填写情况
                        If FBinf.FSDate6 = Nothing Or FBinf.FEDate6 = Nothing Then
                            ErrString = "第 6 行收费区间填写不正确!"
                            Return False
                        End If
                        If Math.Abs(DateDiff(DateInterval.Day, FBinf.FSDate6, FBinf.FEDate6)) + 1 <> FBinf.FQty6 Then
                            ErrString = "参数有误!"
                            Return False
                        End If
                        If FBinf.FQty6 <= 0 Then
                            ErrString = "第 6 行平米数必须大于0"
                            Return False
                        End If
                        If FBinf.FPrice6 <= 0 Then
                            ErrString = "第 6 行单价必须大于0"
                            Return False
                        End If
                        If FBinf.FDays6 <= 0 Then
                            ErrString = "第 6 行天数必须大于0"
                            Return False
                        End If
                        If FBinf.FDays6 * FBinf.FPrice6 * FBinf.FQty6 <> FBinf.FAcc6 Then
                            ErrString = "第 6 行金额有误!"
                            Return False
                        End If
                        '--组合条件
                        FCol += ",FItem6,FItemName6,FSDate6,FEDate6,FQty6,FPrice6,FDays6,FAcc6"
                        FVal += String.Format(",'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}'", FBinf.FItem6, FBinf.FItemName6, FBinf.FSDate6, FBinf.FEDate6, FBinf.FQty6, FBinf.FPrice6, FBinf.FDays6, FBinf.FAcc6)
                    End If

                    '--检查第7条分录
                    If FBinf.FItemName7.Trim <> String.Empty Then
                        If FBinf.FItem7 = Nothing Or FBinf.FItem7 = 0 Then
                            '--增加项目
                            _Bill_Property14_CheckItem(FBinf.FItemName7, FBinf.FQty7, FBinf.FPrice7, FBinf.FItem7, ErrString)
                        End If
                        '--检查各项信息填写情况
                        If FBinf.FSDate7 = Nothing Or FBinf.FEDate7 = Nothing Then
                            ErrString = "第 7 行收费区间填写不正确!"
                            Return False
                        End If
                        If Math.Abs(DateDiff(DateInterval.Day, FBinf.FSDate7, FBinf.FEDate7)) + 1 <> FBinf.FQty7 Then
                            ErrString = "参数有误!"
                            Return False
                        End If
                        If FBinf.FQty7 <= 0 Then
                            ErrString = "第 7 行平米数必须大于0"
                            Return False
                        End If
                        If FBinf.FPrice7 <= 0 Then
                            ErrString = "第 7 行单价必须大于0"
                            Return False
                        End If
                        If FBinf.FDays7 <= 0 Then
                            ErrString = "第 7 行天数必须大于0"
                            Return False
                        End If
                        If FBinf.FDays7 * FBinf.FPrice7 * FBinf.FQty7 <> FBinf.FAcc7 Then
                            ErrString = "第 7 行金额有误!"
                            Return False
                        End If
                        '--组合条件
                        FCol += ",FItem7,FItemName7,FSDate7,FEDate7,FQty7,FPrice7,FDays7,FAcc7"
                        FVal += String.Format(",'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}'", FBinf.FItem7, FBinf.FItemName7, FBinf.FSDate7, FBinf.FEDate7, FBinf.FQty7, FBinf.FPrice7, FBinf.FDays7, FBinf.FAcc7)
                    End If

                    '--检查第8条分录
                    If FBinf.FItemName8.Trim <> String.Empty Then
                        If FBinf.FItem8 = Nothing Or FBinf.FItem8 = 0 Then
                            '--增加项目
                            _Bill_Property14_CheckItem(FBinf.FItemName8, FBinf.FQty8, FBinf.FPrice8, FBinf.FItem8, ErrString)
                        End If
                        '--检查各项信息填写情况
                        If FBinf.FSDate8 = Nothing Or FBinf.FEDate8 = Nothing Then
                            ErrString = "第 8 行收费区间填写不正确!"
                            Return False
                        End If
                        If Math.Abs(DateDiff(DateInterval.Day, FBinf.FSDate8, FBinf.FEDate8)) + 1 <> FBinf.FQty8 Then
                            ErrString = "参数有误!"
                            Return False
                        End If
                        If FBinf.FQty8 <= 0 Then
                            ErrString = "第 8 行平米数必须大于0"
                            Return False
                        End If
                        If FBinf.FPrice8 <= 0 Then
                            ErrString = "第 8 行单价必须大于0"
                            Return False
                        End If
                        If FBinf.FDays8 <= 0 Then
                            ErrString = "第 8 行天数必须大于0"
                            Return False
                        End If
                        If FBinf.FDays8 * FBinf.FPrice8 * FBinf.FQty8 <> FBinf.FAcc8 Then
                            ErrString = "第 8 行金额有误!"
                            Return False
                        End If
                        '--组合条件
                        FCol += ",FItem8,FItemName8,FSDate8,FEDate8,FQty8,FPrice8,FDays8,FAcc8"
                        FVal += String.Format(",'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}'", FBinf.FItem8, FBinf.FItemName8, FBinf.FSDate8, FBinf.FEDate8, FBinf.FQty8, FBinf.FPrice8, FBinf.FDays8, FBinf.FAcc8)
                    End If

                    '--检查第9条分录
                    If FBinf.FItemName9.Trim <> String.Empty Then
                        If FBinf.FItem9 = Nothing Or FBinf.FItem9 = 0 Then
                            '--增加项目
                            _Bill_Property14_CheckItem(FBinf.FItemName9, FBinf.FQty9, FBinf.FPrice9, FBinf.FItem9, ErrString)
                        End If
                        '--检查各项信息填写情况
                        If FBinf.FSDate9 = Nothing Or FBinf.FEDate9 = Nothing Then
                            ErrString = "第 9 行收费区间填写不正确!"
                            Return False
                        End If
                        If Math.Abs(DateDiff(DateInterval.Day, FBinf.FSDate9, FBinf.FEDate9)) + 1 <> FBinf.FQty9 Then
                            ErrString = "参数有误!"
                            Return False
                        End If
                        If FBinf.FQty9 <= 0 Then
                            ErrString = "第 9 行平米数必须大于0"
                            Return False
                        End If
                        If FBinf.FPrice9 <= 0 Then
                            ErrString = "第 9 行单价必须大于0"
                            Return False
                        End If
                        If FBinf.FDays9 <= 0 Then
                            ErrString = "第 9 行天数必须大于0"
                            Return False
                        End If
                        If FBinf.FDays9 * FBinf.FPrice9 * FBinf.FQty9 <> FBinf.FAcc9 Then
                            ErrString = "第 9 行金额有误!"
                            Return False
                        End If
                        '--组合条件
                        FCol += ",FItem9,FItemName9,FSDate9,FEDate9,FQty9,FPrice9,FDays9,FAcc9"
                        FVal += String.Format(",'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}'", FBinf.FItem9, FBinf.FItemName9, FBinf.FSDate9, FBinf.FEDate9, FBinf.FQty9, FBinf.FPrice9, FBinf.FDays9, FBinf.FAcc9)
                    End If

                    '--检查第10条分录
                    If FBinf.FItemName10.Trim <> String.Empty Then
                        If FBinf.FItem10 = Nothing Or FBinf.FItem10 = 0 Then
                            '--增加项目
                            _Bill_Property14_CheckItem(FBinf.FItemName10, FBinf.FQty10, FBinf.FPrice10, FBinf.FItem10, ErrString)
                        End If
                        '--检查各项信息填写情况
                        If FBinf.FSDate10 = Nothing Or FBinf.FEDate10 = Nothing Then
                            ErrString = "第 10 行收费区间填写不正确!"
                            Return False
                        End If
                        If Math.Abs(DateDiff(DateInterval.Day, FBinf.FSDate10, FBinf.FEDate10)) + 1 <> FBinf.FQty10 Then
                            ErrString = "参数有误!"
                            Return False
                        End If
                        If FBinf.FQty10 <= 0 Then
                            ErrString = "第 10 行平米数必须大于0"
                            Return False
                        End If
                        If FBinf.FPrice10 <= 0 Then
                            ErrString = "第 10 行单价必须大于0"
                            Return False
                        End If
                        If FBinf.FDays10 <= 0 Then
                            ErrString = "第 10 行天数必须大于0"
                            Return False
                        End If
                        If FBinf.FDays10 * FBinf.FPrice10 * FBinf.FQty10 <> FBinf.FAcc10 Then
                            ErrString = "第 10 行金额有误!"
                            Return False
                        End If
                        '--组合条件
                        FCol += ",FItem10,FItemName10,FSDate10,FEDate10,FQty10,FPrice10,FDays10,FAcc10"
                        FVal += String.Format(",'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}'", FBinf.FItem10, FBinf.FItemName10, FBinf.FSDate10, FBinf.FEDate10, FBinf.FQty10, FBinf.FPrice10, FBinf.FDays10, FBinf.FAcc10)
                    End If

                    '--检查第11条分录
                    If FBinf.FItemName11.Trim <> String.Empty Then
                        If FBinf.FItem11 = Nothing Or FBinf.FItem11 = 0 Then
                            '--增加项目
                            _Bill_Property14_CheckItem(FBinf.FItemName11, FBinf.FQty11, FBinf.FPrice11, FBinf.FItem11, ErrString)
                        End If
                        '--检查各项信息填写情况
                        If FBinf.FSDate11 = Nothing Or FBinf.FEDate11 = Nothing Then
                            ErrString = "第 11 行收费区间填写不正确!"
                            Return False
                        End If
                        If Math.Abs(DateDiff(DateInterval.Day, FBinf.FSDate11, FBinf.FEDate11)) + 1 <> FBinf.FQty11 Then
                            ErrString = "参数有误!"
                            Return False
                        End If
                        If FBinf.FQty11 <= 0 Then
                            ErrString = "第 11 行平米数必须大于0"
                            Return False
                        End If
                        If FBinf.FPrice11 <= 0 Then
                            ErrString = "第 11 行单价必须大于0"
                            Return False
                        End If
                        If FBinf.FDays11 <= 0 Then
                            ErrString = "第 11 行天数必须大于0"
                            Return False
                        End If
                        If FBinf.FDays11 * FBinf.FPrice11 * FBinf.FQty11 <> FBinf.FAcc11 Then
                            ErrString = "第 11 行金额有误!"
                            Return False
                        End If
                        '--组合条件
                        FCol += ",FItem11,FItemName11,FSDate11,FEDate11,FQty11,FPrice11,FDays11,FAcc11"
                        FVal += String.Format(",'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}'", FBinf.FItem11, FBinf.FItemName11, FBinf.FSDate11, FBinf.FEDate11, FBinf.FQty11, FBinf.FPrice11, FBinf.FDays11, FBinf.FAcc11)
                    End If

                    '--检查第12条分录
                    If FBinf.FItemName12.Trim <> String.Empty Then
                        If FBinf.FItem12 = Nothing Or FBinf.FItem12 = 0 Then
                            '--增加项目
                            _Bill_Property14_CheckItem(FBinf.FItemName12, FBinf.FQty12, FBinf.FPrice12, FBinf.FItem12, ErrString)
                        End If
                        '--检查各项信息填写情况
                        If FBinf.FSDate12 = Nothing Or FBinf.FEDate12 = Nothing Then
                            ErrString = "第 12 行收费区间填写不正确!"
                            Return False
                        End If
                        If Math.Abs(DateDiff(DateInterval.Day, FBinf.FSDate12, FBinf.FEDate12)) + 1 <> FBinf.FQty12 Then
                            ErrString = "参数有误!"
                            Return False
                        End If
                        If FBinf.FQty12 <= 0 Then
                            ErrString = "第 12 行平米数必须大于0"
                            Return False
                        End If
                        If FBinf.FPrice12 <= 0 Then
                            ErrString = "第 12 行单价必须大于0"
                            Return False
                        End If
                        If FBinf.FDays12 <= 0 Then
                            ErrString = "第 12 行天数必须大于0"
                            Return False
                        End If
                        If FBinf.FDays12 * FBinf.FPrice12 * FBinf.FQty12 <> FBinf.FAcc12 Then
                            ErrString = "第 12 行金额有误!"
                            Return False
                        End If
                        '--组合条件
                        FCol += ",FItem12,FItemName12,FSDate12,FEDate12,FQty12,FPrice12,FDays12,FAcc12"
                        FVal += String.Format(",'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}'", FBinf.FItem12, FBinf.FItemName12, FBinf.FSDate12, FBinf.FEDate12, FBinf.FQty12, FBinf.FPrice12, FBinf.FDays12, FBinf.FAcc12)
                    End If


                    '--检查其它参数
                    If FBinf.FAmount <= 0 Then
                        ErrString = "参数错误!"
                        Return False
                    End If
                    FBinf.FOrgid = FUinf.FOrgid
                    If FBinf.FDate = Nothing Then
                        ErrString = "单据日期不正确!"
                        Return False
                    End If
                    '--生成单据号和验证码
                    Dim FLsh As String = String.Empty
                    Dim FVerDate As String = String.Format("{0:yyyyMMdd}", FBinf.FDate)
                    If GetBillMaxNumber(6, FUinf.FOrgid, FLsh, ErrString) = False Then
                        Return False
                    End If
                    If CInt(FLsh) <= 0 Then
                        ErrString = "取单据流水号失败!"
                        Return False
                    End If
                    FLsh = String.Format("{0:000000}", FLsh)
                    FBinf.FBillNo = FVerDate & FLsh
                    FBinf.FVerifyCode = FBinf.FAmount * CDec(Microsoft.VisualBasic.Right(FLsh, 4)) / CDec(FVerDate) * 987654
                    FBinf.FBCode = Nothing
                    FBinf.FBCode = Guid.NewGuid.ToString.ToUpper
                    If FBinf.FBCode.Trim = String.Empty Then
                        ErrString = "生成单据内码失败!"
                        Return False
                    End If
                    sqlstr = String.Format("insert into Bill_Property14(FCid,FName,FCName,FBCode,FBillNo,FVerifyCode,FAmount,FUid,FUName,FCancel,FOrgid{0},FDate,FRDate) values('{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}',0,'{11}'{1},'{12}',GETDATE())", FCol, FVal, FBinf.FCid, FBinf.FName, FBinf.FCName, FBinf.FBCode, FBinf.FBillNo, FBinf.FVerifyCode, FBinf.FAmount, FBinf.FUid, FBinf.FUName, FUinf.FOrgid, FBinf.FDate)
                    If DControl.ExecSQL(sqlstr, ErrString) = False Then
                        Return False
                    End If
                    sqlstr = "select * from Bill_Property14 where FBCode='" & FBinf.FBCode & "'"
                    ds = New DataSet
                    If DControl.QuerySQL(sqlstr, ds, ErrString) = False Then
                        ErrString = String.Format("获取新单据ID失败!{0}错误信息:{1}", vbCrLf, ErrString)
                        Return False
                    End If
                    FBinf.id = ds.Tables(0).Rows(0).Item("id")
                    If FBinf.id <= 0 Then
                        ErrString = String.Format("保存单据失败!{0}错误信息:未知错误", vbCrLf)
                        Return False
                    End If
                    Return True
                Case "Modify"
                    ErrString = "参数错误"
                    Return False
                Case "Verify"
                    '--检查组织
                    ds = New DataSet
                    sqlstr = "select FVid,FUid from Bill_Property14 where id=" & FBinf.id
                    If DControl.QuerySQL(sqlstr, ds, ErrString) = False Then
                        Return False
                    End If
                    If FBinf.FUid <> ds.Tables(0).Rows(0).Item("FUid") Then
                        ErrString = "参数不正确!"
                        Return False
                    End If
                    Dim FUids As String() = Nothing
                    If GetUserPair(FUinf.id, FUids, ErrString) = False Then
                        ErrString = String.Format("获取用户组织失败!{0}错误信息:{1}", vbCrLf, ErrString)
                        Return False
                    End If
                    If FUids.Contains(FBinf.FUid) = False Then
                        ErrString = "当前用户与制单人不在同一组织内,无法收费!"
                        Return False
                    End If
                    '--检查权限
                    If FBinf.FUid = FUinf.id Then
                        '--自己的单据
                        If _User_CheckAuth(FSession, "BILL", "FPDBILLVERIFYMY", ErrString) = False Then
                            ErrString = "没有权限[审核自己录入的物业单据]"
                            Return False
                        End If
                    Else
                        '--其它人的单据
                        If _User_CheckAuth(FSession, "BILL", "FPDBILLVERIFY", ErrString) = False Then
                            ErrString = "没有权限[审核物业单据]"
                            Return False
                        End If
                    End If
                    '--审核状态
                    If ds.Tables(0).Rows(0).Item("FVid") > 0 Then
                        ErrString = "此单据已经收费"
                    End If
                    '--收费
                    sqlstr = String.Format("update Bill_Property14 set FVid={0},FVName='{1}' where id={2}", FUinf.id, FUinf.FName, FBinf.id)
                    Return DControl.ExecSQL(sqlstr, ErrString)
                Case Else
                    ErrString = "参数错误"
                    Return False
            End Select
        Catch ex As Exception
            ErrString = String.Format("保存单据出错!{0}错误信息:{1}", vbCrLf, ex.Message)
            Return False
        End Try
    End Function
#End Region

#Region "获取单据信息"
    Public Function _Bill_Property14_GetBillInfo(ByVal FSession As String, ByRef FBinf As FBillProp14, ByRef ErrString As String) As Boolean Implements IService._Bill_Property14_GetBillInfo
        If FVerifyUser(FSession, ErrString) = False Then
            Return False
        End If
        Try
            If FBinf Is Nothing Then
                ErrString = "参数错误!"
                Return False
            End If
            If FBinf.id <= 0 Then
                ErrString = "单据ID不能为空!"
                Return False
            End If
            Dim FUinf As New FUserInfo
            Dim sqlstr As String = String.Empty
            Dim ds As New DataSet
            Dim t As DataRow = Nothing
            '--读取单据
            sqlstr = "select * from Bill_Property14 where id=" & FBinf.id
            If DControl.QuerySQL(sqlstr, ds, ErrString) = False Then
                ErrString = String.Format("获取单据信息失败!{0}错误信息:{1}", vbCrLf, ErrString)
                Return False
            End If
            If ds.Tables(0).Rows.Count < 1 Then
                ErrString = "未找到指定记录"
                Return False
            End If
            t = ds.Tables(0).Rows(0)
            '--检查权限
            If t.Item("FUid") <> FUinf.id Then
                '--不是制单人
                If _User_CheckAuth(FSession, "BILL", "FPDBILLVIEW", ErrString) = False Then
                    ErrString = String.Format("没有权限!{0}{1}", vbCrLf, ErrString)
                    Return False
                End If
            End If
            '--返回信息
            FBinf.FCid = FControl.cvN(t.Item("FCid"))
            FBinf.FName = FControl.cvN(t.Item("FName"))
            FBinf.FCName = FControl.cvN(t.Item("FCName"))
            FBinf.FBillNo = FControl.cvN(t.Item("FBillNo"))
            FBinf.FBCode = FControl.cvN(t.Item("FBCode"))
            FBinf.FVerifyCode = FControl.cvN(t.Item("FVerifyCode"))
            FBinf.FUid = FControl.cvN(t.Item("FUid"))
            FBinf.FUName = FControl.cvN(t.Item("FUName"))
            FBinf.FVid = FControl.cvN(t.Item("FVid"))
            FBinf.FVName = FControl.cvN(t.Item("FVName"))
            FBinf.FDate = FControl.cvN(t.Item("FDate"))
            FBinf.FRDate = FControl.cvN(t.Item("FRDate"))
            FBinf.FAmount = FControl.cvN(t.Item("FAmount"))
            FBinf.FCancel = FControl.cvN(t.Item("FCancel"))
            FBinf.FPCount = FControl.cvN(t.Item("FPCount"))
            FBinf.FOrgid = FControl.cvN(t.Item("FOrgid"))
            FBinf.FDate = FControl.cvN(t.Item("FDate"))
            FBinf.FRDate = FControl.cvN(t.Item("FRDate"))
            '--分录
            FBinf.FItem1 = FControl.cvN(t.Item("FItem1"))
            FBinf.FItemName1 = FControl.cvN(t.Item("FItemName1"))
            FBinf.FSDate1 = FControl.cvN(t.Item("FSDate1"))
            FBinf.FEDate1 = FControl.cvN(t.Item("FEDate1"))
            FBinf.FDays1 = FControl.cvN(t.Item("FDays1"))
            FBinf.FPrice1 = FControl.cvN(t.Item("FPrice1"))
            FBinf.FQty1 = FControl.cvN(t.Item("FQty1"))
            FBinf.FAcc1 = FControl.cvN(t.Item("FAcc1"))

            FBinf.FItem2 = FControl.cvN(t.Item("FItem2"))
            FBinf.FItemName2 = FControl.cvN(t.Item("FItemName2"))
            FBinf.FSDate2 = FControl.cvN(t.Item("FSDate2"))
            FBinf.FEDate2 = FControl.cvN(t.Item("FEDate2"))
            FBinf.FDays2 = FControl.cvN(t.Item("FDays2"))
            FBinf.FPrice2 = FControl.cvN(t.Item("FPrice2"))
            FBinf.FQty2 = FControl.cvN(t.Item("FQty2"))
            FBinf.FAcc2 = FControl.cvN(t.Item("FAcc2"))

            FBinf.FItem3 = FControl.cvN(t.Item("FItem3"))
            FBinf.FItemName3 = FControl.cvN(t.Item("FItemName3"))
            FBinf.FSDate3 = FControl.cvN(t.Item("FSDate3"))
            FBinf.FEDate3 = FControl.cvN(t.Item("FEDate3"))
            FBinf.FDays3 = FControl.cvN(t.Item("FDays3"))
            FBinf.FPrice3 = FControl.cvN(t.Item("FPrice3"))
            FBinf.FQty3 = FControl.cvN(t.Item("FQty3"))
            FBinf.FAcc3 = FControl.cvN(t.Item("FAcc3"))

            FBinf.FItem4 = FControl.cvN(t.Item("FItem4"))
            FBinf.FItemName4 = FControl.cvN(t.Item("FItemName4"))
            FBinf.FSDate4 = FControl.cvN(t.Item("FSDate4"))
            FBinf.FEDate4 = FControl.cvN(t.Item("FEDate4"))
            FBinf.FDays4 = FControl.cvN(t.Item("FDays4"))
            FBinf.FPrice4 = FControl.cvN(t.Item("FPrice4"))
            FBinf.FQty4 = FControl.cvN(t.Item("FQty4"))
            FBinf.FAcc4 = FControl.cvN(t.Item("FAcc4"))

            FBinf.FItem5 = FControl.cvN(t.Item("FItem5"))
            FBinf.FItemName5 = FControl.cvN(t.Item("FItemName5"))
            FBinf.FSDate5 = FControl.cvN(t.Item("FSDate5"))
            FBinf.FEDate5 = FControl.cvN(t.Item("FEDate5"))
            FBinf.FDays5 = FControl.cvN(t.Item("FDays5"))
            FBinf.FPrice5 = FControl.cvN(t.Item("FPrice5"))
            FBinf.FQty5 = FControl.cvN(t.Item("FQty5"))
            FBinf.FAcc5 = FControl.cvN(t.Item("FAcc5"))

            FBinf.FItem6 = FControl.cvN(t.Item("FItem6"))
            FBinf.FItemName6 = FControl.cvN(t.Item("FItemName6"))
            FBinf.FSDate6 = FControl.cvN(t.Item("FSDate6"))
            FBinf.FEDate6 = FControl.cvN(t.Item("FEDate6"))
            FBinf.FDays6 = FControl.cvN(t.Item("FDays6"))
            FBinf.FPrice6 = FControl.cvN(t.Item("FPrice6"))
            FBinf.FQty6 = FControl.cvN(t.Item("FQty6"))
            FBinf.FAcc6 = FControl.cvN(t.Item("FAcc6"))

            FBinf.FItem7 = FControl.cvN(t.Item("FItem7"))
            FBinf.FItemName7 = FControl.cvN(t.Item("FItemName7"))
            FBinf.FSDate7 = FControl.cvN(t.Item("FSDate7"))
            FBinf.FEDate7 = FControl.cvN(t.Item("FEDate7"))
            FBinf.FDays7 = FControl.cvN(t.Item("FDays7"))
            FBinf.FPrice7 = FControl.cvN(t.Item("FPrice7"))
            FBinf.FQty7 = FControl.cvN(t.Item("FQty7"))
            FBinf.FAcc7 = FControl.cvN(t.Item("FAcc7"))

            FBinf.FItem8 = FControl.cvN(t.Item("FItem8"))
            FBinf.FItemName8 = FControl.cvN(t.Item("FItemName8"))
            FBinf.FSDate8 = FControl.cvN(t.Item("FSDate8"))
            FBinf.FEDate8 = FControl.cvN(t.Item("FEDate8"))
            FBinf.FDays8 = FControl.cvN(t.Item("FDays8"))
            FBinf.FPrice8 = FControl.cvN(t.Item("FPrice8"))
            FBinf.FQty8 = FControl.cvN(t.Item("FQty8"))
            FBinf.FAcc8 = FControl.cvN(t.Item("FAcc8"))

            FBinf.FItem9 = FControl.cvN(t.Item("FItem9"))
            FBinf.FItemName9 = FControl.cvN(t.Item("FItemName9"))
            FBinf.FSDate9 = FControl.cvN(t.Item("FSDate9"))
            FBinf.FEDate9 = FControl.cvN(t.Item("FEDate9"))
            FBinf.FDays9 = FControl.cvN(t.Item("FDays9"))
            FBinf.FPrice9 = FControl.cvN(t.Item("FPrice9"))
            FBinf.FQty9 = FControl.cvN(t.Item("FQty9"))
            FBinf.FAcc9 = FControl.cvN(t.Item("FAcc9"))

            FBinf.FItem10 = FControl.cvN(t.Item("FItem10"))
            FBinf.FItemName10 = FControl.cvN(t.Item("FItemName10"))
            FBinf.FSDate10 = FControl.cvN(t.Item("FSDate10"))
            FBinf.FEDate10 = FControl.cvN(t.Item("FEDate10"))
            FBinf.FDays10 = FControl.cvN(t.Item("FDays10"))
            FBinf.FPrice10 = FControl.cvN(t.Item("FPrice10"))
            FBinf.FQty10 = FControl.cvN(t.Item("FQty10"))
            FBinf.FAcc10 = FControl.cvN(t.Item("FAcc10"))

            FBinf.FItem11 = FControl.cvN(t.Item("FItem11"))
            FBinf.FItemName11 = FControl.cvN(t.Item("FItemName11"))
            FBinf.FSDate11 = FControl.cvN(t.Item("FSDate11"))
            FBinf.FEDate11 = FControl.cvN(t.Item("FEDate11"))
            FBinf.FDays11 = FControl.cvN(t.Item("FDays11"))
            FBinf.FPrice11 = FControl.cvN(t.Item("FPrice11"))
            FBinf.FQty11 = FControl.cvN(t.Item("FQty11"))
            FBinf.FAcc11 = FControl.cvN(t.Item("FAcc11"))

            FBinf.FItem12 = FControl.cvN(t.Item("FItem12"))
            FBinf.FItemName12 = FControl.cvN(t.Item("FItemName12"))
            FBinf.FSDate12 = FControl.cvN(t.Item("FSDate12"))
            FBinf.FEDate12 = FControl.cvN(t.Item("FEDate12"))
            FBinf.FDays12 = FControl.cvN(t.Item("FDays12"))
            FBinf.FPrice12 = FControl.cvN(t.Item("FPrice12"))
            FBinf.FQty12 = FControl.cvN(t.Item("FQty12"))
            FBinf.FAcc12 = FControl.cvN(t.Item("FAcc12"))

            Return True
        Catch ex As Exception
            ErrString = String.Format("查询单据时出现错误!{0}错误信息:{1}", vbCrLf, ErrString)
            Return False
        End Try
    End Function
#End Region

#Region "查询单据"
    Public Function _Bill_Property14_QueryBill(ByVal FSession As String, ByVal FStyle As String, ByVal FOrgid As String, ByVal FSDate As String, ByVal FEDate As String, ByVal FCondition As String, ByRef DsArr As Byte(), ByRef ErrString As String) As Boolean Implements IService._Bill_Property14_QueryBill
        If FVerifyUser(FSession, ErrString) = False Then
            Return False
        End If
        Try
            Dim sqlstr As String = String.Empty
            Dim ds As DataSet = Nothing
            Dim FUinf As New FUserInfo
            Dim FCOrgid As String = String.Empty
            '-取用户信息
            If GetUserInfoBySession(FSession, FUinf, ErrString) = False Then
                ErrString = "取用户信息失败!" & ErrString
                Return False
            End If
            '--组织
            If FUinf.FOrgid <> CInt(FOrgid) Then
                '--不是自己组织
                If _User_CheckAuth(FSession, "BILL", "XXXX", ErrString) = False Then
                    ErrString = "没有权限!"
                    Return False
                End If
            End If
            '--组织
            If FOrgid = 0 Then
                FCOrgid = ""
            Else
                FCOrgid = " and FOrgid=" & FOrgid
            End If
            '--自定义条件
            FCondition = " where " & FCondition
            Select Case FStyle.Trim
                Case "*"
                    sqlstr = "select * from Bill_Property14"
                    FCondition += " and FCancel=0"
                Case "ZF*"
                    sqlstr = "select * from Bill_Property14"
                Case "CN"
                    sqlstr = "select id '内码',FName '交款单位',FCName '交款人',FBillNo '单据号',FDate '日期',FAmount '总金额',FVerifyCode '验证码',FItemName1 '项目1',convert(varchar(120),FSDate1,23) + ' ~ ' + convert(varchar(120),FEDate1,23) '收费区间1',FDays1 '天数1',FPrice1 '单价1',FQty1 '面积1',FAcc1 '金额1',FItemName2 '项目2',convert(varchar(120),FSDate2,23) + ' ~ ' + convert(varchar(120),FEDate2,23) '收费区间2',FDays2 '天数2',FPrice2 '单价2',FQty2 '面积2',FAcc2 '金额2',FItemName3 '项目3',convert(varchar(120),FSDate3,23) + ' ~ ' + convert(varchar(120),FEDate3,23) '收费区间3',FDays3 '天数3',FPrice3 '单价3',FQty3 '面积3',FAcc3 '金额3',FItemName4 '项目4',convert(varchar(120),FSDate4,23) + ' ~ ' + convert(varchar(120),FEDate4,23) '收费区间4',FDays4 '天数4',FPrice4 '单价4',FQty4 '面积4',FAcc4 '金额4',FItemName5 '项目5',convert(varchar(120),FSDate5,23) + ' ~ ' + convert(varchar(120),FEDate5,23) '收费区间5',FDays5 '天数5',FPrice5 '单价5',FQty5 '面积5',FAcc5 '金额5',FItemName6 '项目6',convert(varchar(120),FSDate6,23) + ' ~ ' + convert(varchar(120),FEDate6,23) '收费区间6',FDays6 '天数6',FPrice6 '单价6',FQty6 '面积6',FAcc6 '金额6',FItemName7 '项目7',convert(varchar(120),FSDate7,23) + ' ~ ' + convert(varchar(120),FEDate7,23) '收费区间7',FDays7 '天数7',FPrice7 '单价7',FQty7 '面积7',FAcc7 '金额7',FItemName8 '项目8',convert(varchar(120),FSDate8,23) + ' ~ ' + convert(varchar(120),FEDate8,23) '收费区间8',FDays8 '天数8',FPrice8 '单价8',FQty8 '面积8',FAcc8 '金额8',FItemName9 '项目9',convert(varchar(120),FSDate9,23) + ' ~ ' + convert(varchar(120),FEDate9,23) '收费区间9',FDays9 '天数9',FPrice9 '单价9',FQty9 '面积9',FAcc9 '金额9',FItemName10 '项目10',convert(varchar(120),FSDate10,23) + ' ~ ' + convert(varchar(120),FEDate10,23) '收费区间10',FDays10 '天数10',FPrice10 '单价10',FQty10 '面积10',FAcc10 '金额10',FItemName11 '项目11',convert(varchar(120),FSDate11,23) + ' ~ ' + convert(varchar(120),FEDate11,23) '收费区间11',FDays11 '天数11',FPrice11 '单价11',FQty11 '面积11',FAcc11 '金额11',FItemName12 '项目12',convert(varchar(120),FSDate12,23) + ' ~ ' + convert(varchar(120),FEDate12,23) '收费区间12',FDays12 '天数12',FPrice12 '单价12',FQty12 '面积12',FAcc12 '金额12',FItemName13 '项目13',convert(varchar(120),FSDate13,23) + ' ~ ' + convert(varchar(120),FEDate13,23) '收费区间13',FDays13 '天数13',FPrice13 '单价13',FQty13 '面积13',FAcc13 '金额13',FItemName14 '项目14',convert(varchar(120),FSDate14,23) + ' ~ ' + convert(varchar(120),FEDate14,23) '收费区间14',FDays14 '天数14',FPrice14 '单价14',FQty14 '面积14',FAcc14 '金额14',FItemName15 '项目15',convert(varchar(120),FSDate15,23) + ' ~ ' + convert(varchar(120),FEDate15,23) '收费区间15',FDays15 '天数15',FPrice15 '单价15',FQty15 '面积15',FAcc15 '金额15',FUName '制单',FVName '收费',FPCount '打印次数'"
                    FCondition += " and FCancel=0"
                Case "ZFCN"
                    sqlstr = "select id '内码',FName '交款单位',FCName '交款人',FBillNo '单据号',FDate '日期',FAmount '总金额',FVerifyCode '验证码',FItemName1 '项目1',convert(varchar(120),FSDate1,23) + ' ~ ' + convert(varchar(120),FEDate1,23) '收费区间1',FDays1 '天数1',FPrice1 '单价1',FQty1 '面积1',FAcc1 '金额1',FItemName2 '项目2',convert(varchar(120),FSDate2,23) + ' ~ ' + convert(varchar(120),FEDate2,23) '收费区间2',FDays2 '天数2',FPrice2 '单价2',FQty2 '面积2',FAcc2 '金额2',FItemName3 '项目3',convert(varchar(120),FSDate3,23) + ' ~ ' + convert(varchar(120),FEDate3,23) '收费区间3',FDays3 '天数3',FPrice3 '单价3',FQty3 '面积3',FAcc3 '金额3',FItemName4 '项目4',convert(varchar(120),FSDate4,23) + ' ~ ' + convert(varchar(120),FEDate4,23) '收费区间4',FDays4 '天数4',FPrice4 '单价4',FQty4 '面积4',FAcc4 '金额4',FItemName5 '项目5',convert(varchar(120),FSDate5,23) + ' ~ ' + convert(varchar(120),FEDate5,23) '收费区间5',FDays5 '天数5',FPrice5 '单价5',FQty5 '面积5',FAcc5 '金额5',FItemName6 '项目6',convert(varchar(120),FSDate6,23) + ' ~ ' + convert(varchar(120),FEDate6,23) '收费区间6',FDays6 '天数6',FPrice6 '单价6',FQty6 '面积6',FAcc6 '金额6',FItemName7 '项目7',convert(varchar(120),FSDate7,23) + ' ~ ' + convert(varchar(120),FEDate7,23) '收费区间7',FDays7 '天数7',FPrice7 '单价7',FQty7 '面积7',FAcc7 '金额7',FItemName8 '项目8',convert(varchar(120),FSDate8,23) + ' ~ ' + convert(varchar(120),FEDate8,23) '收费区间8',FDays8 '天数8',FPrice8 '单价8',FQty8 '面积8',FAcc8 '金额8',FItemName9 '项目9',convert(varchar(120),FSDate9,23) + ' ~ ' + convert(varchar(120),FEDate9,23) '收费区间9',FDays9 '天数9',FPrice9 '单价9',FQty9 '面积9',FAcc9 '金额9',FItemName10 '项目10',convert(varchar(120),FSDate10,23) + ' ~ ' + convert(varchar(120),FEDate10,23) '收费区间10',FDays10 '天数10',FPrice10 '单价10',FQty10 '面积10',FAcc10 '金额10',FItemName11 '项目11',convert(varchar(120),FSDate11,23) + ' ~ ' + convert(varchar(120),FEDate11,23) '收费区间11',FDays11 '天数11',FPrice11 '单价11',FQty11 '面积11',FAcc11 '金额11',FItemName12 '项目12',convert(varchar(120),FSDate12,23) + ' ~ ' + convert(varchar(120),FEDate12,23) '收费区间12',FDays12 '天数12',FPrice12 '单价12',FQty12 '面积12',FAcc12 '金额12',FItemName13 '项目13',convert(varchar(120),FSDate13,23) + ' ~ ' + convert(varchar(120),FEDate13,23) '收费区间13',FDays13 '天数13',FPrice13 '单价13',FQty13 '面积13',FAcc13 '金额13',FItemName14 '项目14',convert(varchar(120),FSDate14,23) + ' ~ ' + convert(varchar(120),FEDate14,23) '收费区间14',FDays14 '天数14',FPrice14 '单价14',FQty14 '面积14',FAcc14 '金额14',FItemName15 '项目15',convert(varchar(120),FSDate15,23) + ' ~ ' + convert(varchar(120),FEDate15,23) '收费区间15',FDays15 '天数15',FPrice15 '单价15',FQty15 '面积15',FAcc15 '金额15',FUName '制单',FVName '收费',FPCount '打印次数'"
                    FCondition += " and FCancel=0"
                Case Else
                    ErrString = "参数错误!"
                    Return False
            End Select
            '--组合条件
            sqlstr += FCondition
            sqlstr += FCOrgid
            sqlstr += String.Format(" and FDate>='{0:yyyy-MM-dd} 00:00:00' and FDate<='{1:yyyy-MM-dd} 23:59:59'")
            ds = New DataSet
            '--查询
            If DControl.QuerySQL(sqlstr, ds, ErrString) = False Then
                ErrString = String.Format("查询单据时出现错误!{0}错误信息:{1}", vbCrLf, ErrString)
                Return False
            End If
            '--处理DATASET
            DsArr = FControl.CvtDs(ds)
            '--返回
            Return True
        Catch ex As Exception
            ErrString = String.Format("查询时出现错误!{0}错误信息:{1}", vbCrLf, ex.Message)
            Return False
        End Try
    End Function
#End Region

#Region "作废单据"
    Public Function _Bill_Property14_Cancel(ByVal FSession As String, ByVal FID As String, ByRef ErrString As String) As Boolean Implements IService._Bill_Property14_Cancel
        If FVerifyUser(FSession, ErrString) = False Then
            Return False
        End If
        Try
            Dim sqlstr As String = Nothing
            Dim ds As New DataSet
            Dim FUinf As New FUserInfo
            Dim t As DataRow = Nothing
            If GetUserInfoBySession(FSession, FUinf, ErrString) = False Then
                ErrString = "获取用户信息失败!"
                Return False
            End If
            If FID.Trim = Nothing Or FID.Trim = "0" Then
                ErrString = "参数错误!"
                Return False
            End If
            '--查询单据
            sqlstr = "select * from Bill_Property14 where id=" & FID.Trim
            If DControl.QuerySQL(sqlstr, ds, ErrString) = False Then
                ErrString = String.Format("获取单据信息失败!{0}错误信息:{1}", vbCrLf, ErrString)
                Return False
            End If
            If ds.Tables(0).Rows.Count < 1 Then
                ErrString = "未找到指定记录!"
                Return False
            End If
            t = ds.Tables(0).Rows(0)
            '--检查权限
            If _User_CheckAuth(FSession, "BILL", "FPDBILLCANCEL", ErrString) = False Then
                ErrString = "没有权限!"
                Return False
            End If
            '--非自己的单据权限
            If FUinf.id <> t.Item("FUID") Then
                '--检查全部权限
                If _User_CheckAuth(FSession, "BILL", "FPDBILLCANCELA", ErrString) = False Then
                    ErrString = "没有权限!"
                    Return False
                End If
            End If
            '--非自己单位
            If FUinf.FOrgid <> t.Item("FOrgid") Then
                If _User_CheckAuth(FSession, "BILL", "XXXXXX", ErrString) = False Then
                    ErrString = "没有权限!"
                    Return False
                End If
            End If
            '--作废单据
            sqlstr = "update Bill_Property14 set FCancel=1 where id=" & FID.Trim
            If DControl.ExecSQL(sqlstr, ErrString) = False Then
                ErrString = String.Format("作废单据失败!{0}错误信息:{1}", vbCrLf, ErrString)
                Return False
            End If
            DControl.WriteSysLog("BILL", FUinf.id, FUinf.FRName, "作废单据", "作废地下层物业收据 单号:" & t.Item("FBillNo"), 1)
            Return True
        Catch ex As Exception
            ErrString = String.Format("作废单据失败!{0}错误信息:{1}", vbCrLf, ex.Message)
            Return False
        End Try
    End Function
#End Region

#Region "增加打印次数"
    Public Function _Bill_Property14_AddPrintCount(ByVal FSession As String, ByVal FID As String, ByRef FPCount As Integer, ByRef ErrString As String) As Boolean Implements IService._Bill_Property14_AddPrintCount
        If FVerifyUser(FSession, ErrString) = False Then
            Return False
        End If
        Try
            Dim sqlstr As String = String.Empty
            Dim ds As New DataSet
            Dim FUinf As New FUserInfo
            If FID.Trim = String.Empty Or FID.Trim = "0" Then
                ErrString = "参数错误"
                Return False
            End If
            If GetUserInfoBySession(FSession, FUinf, ErrString) = False Then
                ErrString = "读取用户信息失败!"
                Return False
            End If
            '--读取单据
            Dim FBInf As New FBillProp14
            If _Bill_Property14_GetBillInfo(FSession, FBInf, ErrString) = False Then
                ErrString = String.Format("读取单据信息失败!{0}错误信息:{1}", vbCrLf, ErrString)
                Return False
            End If
            '--检查权限
            If FBInf.FVid < 1 Then
                ErrString = "此单据未收费"
                Return False
            End If
            If FBInf.FVid <> FUinf.id Then
                If _User_CheckAuth(FSession, "BILL", "SSSSS", ErrString) = False Then
                    ErrString = "没有权限"
                    Return False
                End If
            End If
            If FBInf.FPCount > 0 Then
                '--打印以前单据
                If _User_CheckAuth(FSession, "BILL", "FPDBILLPRINT", ErrString) = False Then
                    ErrString = "没有权限"
                    Return False
                End If
            End If
            '--非当前用户所属组织
            If FBInf.FOrgid <> FUinf.FOrgid Then
                '--判断管理员
                If _User_CheckAuth(FSession, "BILL", "SSSSSSSS", ErrString) = False Then
                    ErrString = "只能打印本单位的单据!"
                    Return False
                End If
            End If
            '--增加打印次数
            sqlstr = "update Bill_Property14 set FPCount=FPCount+1 output inserted.FPCount where id=" & FID.Trim
            ds = New DataSet
            If DControl.QuerySQL(sqlstr, ds, ErrString) = False Then
                ErrString = String.Format("打印失败!{0}错误信息:{1}", vbCrLf, ErrString)
                Return False
            End If
            FPCount = ds.Tables(0).Rows(0).Item("FPCount")
            Return True
        Catch ex As Exception
            ErrString = String.Format("打印单据失败!{0}错误信息:{1}", vbCrLf, ex.Message)
            Return False
        End Try
    End Function
#End Region
End Class
